<!--领料单重构-->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :search="search"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
      <template slot="menuLeft">
        <!-- <el-button type="success" size="small" icon="el-icon-s-promotion" v-if="permission.materialRequisition_outBound" @click="handleOutBound">出库</el-button> -->
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
        <!-- <el-button type="success" size="small" icon="el-icon-d-arrow-right" v-if="permission.materialRequisition_generatePreMaterial" @click="handleGeneratePreMaterialList"
          >生成备料单</el-button
        > -->
      </template>
      <template slot-scope="{ row }" slot="menu">
        <el-button
          v-if="permission.materialRequisition_view"
          type="text"
          icon="el-icon-view"
          size="small"
          plain
          style="border: 0; background-color: transparent !important"
          @click.stop="handleView(row)"
          >详情
        </el-button>

        <el-button type="text" icon="el-icon-view" size="small" plain style="border: 0; background-color: transparent !important" @click.stop="handlePackBoxView(row)"
          >包装详情
        </el-button>
      </template>
    </avue-crud>

    <!-- 出库 -->
    <el-dialog
      custom-class="outBoundDialog"
      append-to-body
      :close-on-click-modal="false"
      title="领料单出库"
      :visible.sync="outBoundDialog.visible"
      v-if="outBoundDialog.visible"
      width="90%"
      top="7vh"
      @close="outBoundClose"
    >
      <avue-crud
        :option="outBoundDialog.option"
        :table-loading="outBoundDialog.loading"
        :data="outBoundDialog.tableData"
        :page.sync="outBoundDialog.page"
        :search.sync="outBoundDialog.search"
        :before-open="beforeOpen"
        v-model="outBoundDialog.form"
        ref="outBoundTableCrud"
        :key="timer"
      >
        <template slot="needOutboundQuantity" slot-scope="{ row }">
          <avue-input-number size="mini" v-model="row.needOutboundQuantity" :minRows="0" :maxRows="row.alreadyPickingQuantity - row.alreadyDeliveryQuantity"></avue-input-number>
        </template>
      </avue-crud>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" icon="el-icon-check" @click="handleSubmit">出库</el-button>
        <el-button size="small" icon="el-icon-delete" @click="handleReset">取消</el-button>
      </span>
    </el-dialog>

    <!--  包装详情 -->
    <el-dialog
      custom-class="packBoxDialog"
      append-to-body
      :close-on-click-modal="false"
      title="包装详情"
      :visible.sync="packBoxDialog.visible"
      v-if="packBoxDialog.visible"
      width="90%"
      top="7vh"
    >
      <avue-crud
        :option="packBoxDialog.option"
        :table-loading="packBoxDialog.loading"
        :data="packBoxDialog.tableData"
        :page.sync="packBoxDialog.page"
        v-model="sheetForm"
        ref="packBoxTableCrud"
        :key="timer"
      >
      </avue-crud>
    </el-dialog>

    <!--  详情  -->
    <el-dialog
      custom-class="baseDialog"
      append-to-body
      :close-on-click-modal="false"
      title="详情"
      :visible.sync="baseDialog.visible"
      v-if="baseDialog.visible"
      width="90%"
      top="7vh"
    >
      <div class="titleBar">领料单号：{{ rowData.sheetNo }}&nbsp; &nbsp;&nbsp; &nbsp;关联备料单号：{{ rowData.mplNo }}</div>
      <avue-crud :option="baseDialog.option" :table-loading="baseDialog.loading" :data="baseDialog.tableData" ref="baseTableCrud" :key="timer"> </avue-crud>
    </el-dialog>

    <!-- 备料规则配置 -->
    <el-dialog
      custom-class="ruleDialog"
      append-to-body
      :close-on-click-modal="false"
      title="备料规则配置"
      :visible.sync="preMaterialRuleDialog.visible"
      v-if="preMaterialRuleDialog.visible"
      width="40%"
      top="7vh"
    >
      <el-tabs v-model="preMaterialRuleDialog.activeName" type="card">
        <el-tab-pane label="备料分析配置" name="first">
          <el-checkbox v-model="preMaterialRuleDialog.form.isFifo" :disabled="true">先进先出</el-checkbox>
          <el-tooltip class="item" effect="dark" content="启用后则强控按先进先出的推荐批次出库" placement="top-start">
            <i class="header-icon el-icon-info"></i>
          </el-tooltip>
        </el-tab-pane>
        <el-tab-pane label="拆分备料单规则" name="second">
          <el-row class="ruleRowForm">
            <el-radio v-model="preMaterialRuleDialog.form.splitType" border label="WAREHOUSE" size="mini">仓库</el-radio>
            <el-tooltip class="item" effect="dark" content="根据物料所在仓库等级进行拆分" placement="top-start">
              <i class="header-icon el-icon-info"></i>
            </el-tooltip>
            <span>仓库拆分等级：</span>
            <el-select v-model="preMaterialRuleDialog.form.cangkuValue" placeholder="请选择仓库拆分等级" size="mini">
              <el-option v-for="item in preMaterialRuleDialog.form.cangkuLevelList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </el-row>

          <el-row class="ruleRowForm">
            <el-radio v-model="preMaterialRuleDialog.form.splitType" border label="PEOPLE" size="mini">人员</el-radio>
            <el-tooltip class="item" effect="dark" content="根据仓库等级所对应的负责人进行拆分" placement="top-start">
              <i class="header-icon el-icon-info"></i>
            </el-tooltip>
            <span>仓库拆分等级：</span>
            <el-select v-model="preMaterialRuleDialog.form.renyuanValue" placeholder="请选择仓库拆分等级" size="mini">
              <el-option v-for="item in preMaterialRuleDialog.form.cangkuLevelList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </el-row>

          <el-row class="ruleRowForm">
            <el-radio v-model="preMaterialRuleDialog.form.splitType" border label="SECTION" size="mini">工段</el-radio>
            <el-tooltip class="item" effect="dark" content="ERP同步的领料单据有工段，比如SMT, DIP，组装等工段；按工段拆分" placement="top-start">
              <i class="header-icon el-icon-info"></i>
            </el-tooltip>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick type="primary" size="small" @click="saveRule" icon="el-icon-circle-plus-outline">保 存 </el-button>
        <el-button @click="cancelRule" size="small" icon="el-icon-circle-close">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 新增备料单 -->
    <addDialog
      ref="add"
      :visible="addDialog.visible"
      @closeDialog="addDialog.visible = false"
      @openRuleDialog="handleOpenRuleDialog"
      @generateSuccess="generateSuccess"
    ></addDialog>
    <global-modal-template :visibile.sync="visibile" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"> </global-modal-template>
    <export-comp ref="exportComp" page-api-url="mes-warehouse/sheet-detail/picking-page" :option="option" :page="page" :query="query" file-name="领料单"> </export-comp>
  </basic-container>
</template>

<script>
import { getList, getDetail, handleInventory, getPackBoxDetail, getOutboundList } from '@/api/warehouse/materialRequisition';
import { submitRule, searchRule } from '@/api/warehouse/preMaterialList';
import exportComp from '@/components/export-comp';
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
import { getPrinter } from '@/api/admin/barcode-record';
import GlobalModalTemplate from '@/components/common-modal-template/global-modal-template.vue';
import addDialog from './preMaterialList/addDialog.vue';
export default {
  components: {
    GlobalModalTemplate,
    exportComp,
    userTableConfig,
    addDialog
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'MATERIALREQUISITION',
      visibile: false,
      modalName: '',
      timer: new Date().getTime(), //不同内容使用同一个模态框结构，key值不同需要重新请求渲染数据，否则会请求到上一个使用的数据内容
      form: {},
      search: {},
      query: {
        descs: 'create_time'
      },
      sheetForm: {},
      properties: {},
      loading: false,
      detailLoading: false,
      title: '',
      tableOption: {}, //公用模态框配置信息
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      showDialog: false,
      data: [],
      sheetData: [],
      option: {
        rowKey: 'sheetId',
        calcHeight: 30,
        height: 'calc(100vh - 440px)',
        tip: false,
        searchShow: true,
        searchMenuPosition: 'right',
        searchMenuSpan: 4,
        reserveSelection: true,
        dialogClickModal: false,
        border: true,
        viewBtn: false,
        addBtn: false,
        selection: true,
        printBtn: false,
        editBtn: false,
        delBtn: false,
        index: false,
        searchSpan: 6,
        columnBtn: false,
        menuWidth: 200,
        column: [
          {
            label: '单据类型',
            prop: 'sheetType',
            type: 'select',
            width: 100,
            searchOrder: 1,
            dicData: [
              {
                label: '用料清单',
                value: 'IMO'
              },
              {
                label: '领料单',
                value: 'RO'
              },
              {
                label: '补料单',
                value: 'ROB'
              }
            ],
            // dicUrl: '/api/blade-system/dict/dictionary?code=sheet_type',
            // props: {
            //   label: 'dictValue',
            //   value: 'dictKey'
            // },
            search: true
          },
          {
            label: '单号',
            prop: 'sheetNo',
            width: 150,
            searchOrder: 2,
            search: true
          },
          {
            label: '备料单号',
            prop: 'mplNo',
            searchOrder: 9,
            width: 150,
            search: true
          },
          {
            label: '工单号',
            prop: 'workOrderNo',
            searchOrder: 4,
            search: true
          },
          {
            label: '生产订单',
            prop: 'productionOrderNo',
            searchOrder: 3,
            search: true
          },
          {
            label: '车间部门',
            prop: 'deptName',
            searchOrder: 8,
            search: true
          },
          {
            label: '物料名称',
            prop: 'partName',
            searchOrder: 5,
            hide: true,
            search: true
          },
          {
            label: '物料编码',
            prop: 'partNo',
            searchOrder: 6,
            hide: true,
            search: true
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            width: 100,
            dicData: [
              { label: '已发料', value: 0 },
              { label: '待备料', value: 1 },
              { label: '发料中', value: 2 },
              { label: '备料中', value: 3 },
              { label: '待拣货', value: 4 },
              { label: '拣货中', value: 5 },
              { label: '待发料', value: 6 }
            ]
          },
          {
            label: '领料人',
            prop: 'picker',
            width: 100,
            searchOrder: 7,
            search: true
          }
        ]
      },
      packBoxDialog: {
        visible: false,
        loading: false,
        tableData: [],
        page: {
          pageSize: 20,
          currentPage: 1,
          total: 0
        },
        option: {
          tip: false,
          searchShow: true,
          searchSpan: 4,
          searchMenuSpan: 6,
          dialogClickModal: false,
          height: '400',
          border: true,
          addBtn: false,
          editBtn: false,
          viewBtn: false,
          cancelBtn: false,
          saveBtn: false,
          selection: false,
          menu: false,
          page: true,
          index: true,
          indexLabel: '序号',
          refreshBtn: false,
          expandBtn: false,
          columnBtn: false,
          column: [
            {
              label: '包装条码',
              prop: 'packingSequenceNumber',
              overHidden: true
            },
            {
              label: '物料编码',
              prop: 'partNo',
              type: 'search'
            },
            {
              label: '物料名称',
              prop: 'partName'
            },

            {
              label: '储位',
              prop: 'areaName'
            },
            {
              label: '批次',
              prop: 'lotDate',
              overHidden: true
            },
            {
              label: '品牌',
              prop: 'materialBrand',
              width: 150
            },
            {
              label: 'D/C',
              prop: 'dateCode',
              overHidden: true
            },
            {
              label: '数量',
              prop: 'packingQuantity',
              width: 100
            },
            {
              label: '包装状态',
              prop: 'packingStatus',
              width: 100,
              type: 'select',
              dataType: 'string',
              props: {
                label: 'dictValue',
                value: 'dictKey'
              },
              dicUrl: '/api/blade-system/dict/dictionary?code=pack_status'
            },
            {
              label: '退料数量',
              prop: 'returnPackingQuantity'
            },
            {
              label: '实际用量',
              prop: 'returnUsedQuantity'
            }
          ]
        }
      },
      outBoundDialog: {
        visible: false,
        loading: false,
        tableData: [],
        search: {},
        form: {},
        page: {
          pageSize: 20,
          currentPage: 1,
          total: 0
        },
        option: {
          calcHeight: 30,
          height: 400,
          maxHeight: 400,
          tip: false,
          page: false,
          searchShow: true,
          searchMenuPosition: 'right',
          searchMenuSpan: 4,
          dialogClickModal: false,
          border: true,
          viewBtn: false,
          addBtn: false,
          selection: false,
          printBtn: false,
          editBtn: false,
          delBtn: false,
          index: false,
          searchSpan: 5,
          columnBtn: false,
          refreshBtn: false,
          searchBtn: false,
          emptyBtn: false,
          expandBtn: false,
          searchIcon: false,
          menu: false,
          column: [
            {
              label: '领料人',
              prop: 'picker',
              searchSpan: 6,
              type: 'search',
              placeholder: '请扫领料人工卡条码',
              hide: true,
              search: true,
              searchRules: [
                {
                  required: false,
                  message: '请扫领料人工卡条码',
                  trigger: 'blur'
                }
              ],
              appendClick: () => {
                this.openUserCommonModal({
                  type: 'picker'
                });
              }
            },
            {
              label: '领料单号',
              prop: 'sheetNo'
            },
            {
              label: '工单号',
              prop: 'workOrderNo'
            },
            {
              label: '生产订单号',
              prop: 'productionOrderNo'
            },
            {
              label: '物料名称',
              prop: 'partName'
            },
            {
              label: '物料编码',
              prop: 'partNo'
            },
            {
              label: 'Bom版本',
              width: 80,
              prop: 'bomVersion'
            },
            {
              label: '需求数量',
              prop: 'requireQuantity'
            },
            {
              label: '已拣货数量',
              prop: 'alreadyPickingQuantity'
            },
            {
              label: '已发料数量',
              prop: 'alreadyDeliveryQuantity'
            },
            {
              label: '状态',
              prop: 'sheetDetailStatusName',
              width: 100
            },
            {
              label: '出库数量',
              prop: 'needOutboundQuantity',
              width: 150
            }
          ]
        }
      },
      baseDialog: {
        visible: false,
        loading: false,
        tableData: [],
        option: {
          tip: false,
          searchShow: true,
          searchSpan: 4,
          searchMenuSpan: 6,
          dialogClickModal: false,
          height: '400',
          border: true,
          addBtn: false,
          editBtn: false,
          viewBtn: false,
          cancelBtn: false,
          saveBtn: false,
          selection: false,
          menu: false,
          page: true,
          index: true,
          indexLabel: '序号',
          refreshBtn: false,
          expandBtn: false,
          columnBtn: false,
          column: [
            {
              label: '物料编码',
              prop: 'partNo',
              type: 'search'
            },
            {
              label: '物料名称',
              prop: 'partName'
            },
            {
              label: '物料规格',
              prop: 'partSpec'
            },
            {
              label: '工段',
              prop: 'sectionName'
            },
            {
              label: '批次',
              prop: 'vendorLotNo',
              overHidden: true
            },
            {
              label: 'D/C',
              prop: 'dateCode',
              overHidden: true
            },
            {
              label: '品牌',
              prop: 'materialBrand',
              width: 150
            },

            {
              label: '需求数量',
              prop: 'requireQuantity',
              width: 100
            },
            {
              label: '已发料数量',
              prop: 'alreadyDeliveryQuantity',
              width: 100
            },
            {
              label: '物料状态',
              prop: 'sheetDetailStatusName',
              width: 100
              // width: 100,
              // type: 'select',
              // dataType: 'string',
              // props: {
              //   label: 'dictValue',
              //   value: 'dictKey'
              // },
              // dicUrl: '/api/blade-system/dict/dictionary?code=pack_status'
            },
            {
              label: '退料数量',
              prop: 'alreadyReturnAllQuantity'
            },
            {
              label: '实际数量',
              prop: 'alreadyUsedAllQuantity'
            }
          ]
        }
      },
      rowData: {},
      labelTemplateId: '',
      printerId: '',
      addDialog: {
        visible: false
      },
      preMaterialRuleDialog: {
        visible: false,
        activeName: 'first',
        form: {
          isFifo: true,
          splitType: 'WAREHOUSE',
          cangkuValue: '',
          renyuanValue: '',
          cangkuLevelList: [
            { value: 1, label: 'L1' },
            { value: 2, label: 'L2' },
            { value: 3, label: 'L3' },
            { value: 4, label: 'L4' },
            { value: 5, label: 'L5' }
          ]
        }
      }
    };
  },
  async mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
    const printer = await this.getDefaultPrinter();
    const { labelTemplateId = '', printerId = '' } = printer;
    this.labelTemplateId = labelTemplateId;
    this.printerId = printerId;
    this.getGlobalRules();
    if (this.$route.query.sheetNo) {
      this.$set(this.search, 'sheetNo', this.$route.query.sheetNo);
      this.query['sheetNo'] = this.$route.query.sheetNo;
      this.onLoad(this.page);
      this.$route.path = '/warehouse/productrefactor/materialRequisition';
    }
  },
  computed: {
    ...mapGetters(['permission', 'userInfo']),
    permissionList() {
      return {
        // addBtn: this.vaildData(this.permission.pickingListManage_add, false),
        viewBtn: this.vaildData(this.permission.materialRequisition_view, false)
        // delBtn: this.vaildData(this.permission.pickingListManage_delete, false),
        // editBtn: this.vaildData(this.permission.pickingListManage_edit, false)
      };
    }
  },
  methods: {
    async getDefaultPrinter() {
      const { user_id } = this.userInfo;
      try {
        const res = await getPrinter({ id: user_id });
        return res.data.data;
      } catch (e) {
        console.warn(e);
      }
    },
    beforeOpen(done, type) {
      if (['edit', 'view'].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      // params.sheetTypeStrList = 'RO';
      params.descs = 'create_time';
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;

        this.data = data.records;
        this.loading = false;
      });
    },
    handleView(row) {
      this.baseDialog.visible = true;
      this.baseDialog.loading = true;
      this.rowData = structuredClone(row);
      getDetail(row.sheetId)
        .then((res) => {
          let data = res.data.data;
          this.baseDialog.tableData = data;
          this.baseDialog.loading = false;
        })
        .catch((err) => {});
    },
    handlePackBoxView(row) {
      this.packBoxDialog.visible = true;
      this.getListData(row.sheetId);
    },
    //  获取包装详情
    getListData(sheetId) {
      this.packBoxDialog.tableData = [];
      this.packBoxDialog.loading = true;
      getPackBoxDetail(sheetId).then((res) => {
        const data = res.data.data;
        this.packBoxDialog.tableData = data;
        this.packBoxDialog.loading = false;
      });
    },
    hasDuplicates(arr) {
      return new Set(arr).size !== arr.length;
    },
    // 出库 发料中，待发料时，才能出库
    handleOutBound() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return false;
      }
      let sheetNoArray = this.selectionList.map((item) => item.sheetNo);
      let isRepeatData = this.hasDuplicates(sheetNoArray);
      if (this.selectionList.length > 1 && !isRepeatData) {
        this.$message.warning('勾选数据中出现多个领料单，请重新选择');
        return false;
      }

      let isAllowOutBound = this.selectionList.every((list) => {
        return list.status == 2 || list.status == 6;
      });
      if (!isAllowOutBound) {
        this.$message.warning('领料单状态为发料中或待发料的才能进行出库！');
        return false;
      }

      this.outBoundDialog.visible = true;
      // getOutboundList(this.outBoundDialog.page.currentPage, this.outBoundDialog.page.pageSize, {
      getOutboundList(1, 1000, {
        sheetIdList: this.selectionList.map((item) => item.sheetId)
      })
        .then((res) => {
          let data = res.data.data;
          this.outBoundDialog.tableData = data.records;
          this.outBoundDialog.page.total = data.total;
          console.log('data', data);
        })
        .catch((err) => {});
    },
    handleSubmit() {
      let sheetDetailList = this.outBoundDialog.tableData.map((item) => {
        return {
          id: item.sheetDetailId,
          partMasterId: item.partMasterId,
          operationQuantity: item.needOutboundQuantity
        };
      });
      handleInventory({
        transactionType: 'OUTBOUND',
        sheetType: 'RO',
        sheetId: this.outBoundDialog.tableData[0].sheetId,
        sheetNo: this.outBoundDialog.tableData[0].sheetNo,
        sheetDetailList: sheetDetailList,
        equipmentId: this.printerId,
        labelTemplateId: this.labelTemplateId
      })
        .then((res) => {
          this.$message.success('出库成功');
          this.outBoundDialog.visible = false;
          this.onLoad(this.page);
          this.selectionClear();
        })
        .catch((err) => {});
    },
    handleReset() {
      this.outBoundDialog.visible = false;
    },
    // 生产备料单
    handleGeneratePreMaterialList() {
      this.addDialog.visible = true;
      this.$refs.add.addDialog.title = '新增备料单';
      // this.$refs.add.isFifo = this.preMaterialRuleDialog.form.isFifo;
    },
    // 生成备料单成功
    generateSuccess() {
      this.onLoad(this.page);
    },
    handleOpenRuleDialog(type) {
      this.preMaterialRuleType = type;
      this.preMaterialRuleDialog.activeName = 'first';
      this.preMaterialRuleDialog.visible = true;
      // 查询全局备料规则配置
      this.getGlobalRules();
    },
    getGlobalRules() {
      // 查询全局备料规则配置
      searchRule()
        .then((res) => {
          let data = res.data.data;
          let prepareRuleData = data.find((d) => d.type == 1);
          let splitRuleData = data.find((d) => d.type == 2);
          if (prepareRuleData) {
            let data = JSON.parse(prepareRuleData.content || '{}');
            this.preMaterialRuleDialog.form.isFifo = data.isFifo;
          }
          if (splitRuleData) {
            let data = JSON.parse(splitRuleData.content || '{}');
            this.preMaterialRuleDialog.form.splitType = data.splitType;
            if (this.preMaterialRuleDialog.form.splitType == 'WAREHOUSE') {
              this.preMaterialRuleDialog.form.cangkuValue = Number(data.splitLevelValue);
            }
            if (this.preMaterialRuleDialog.form.splitType == 'PEOPLE') {
              this.preMaterialRuleDialog.form.renyuanValue = Number(data.splitLevelValue);
            }
          }
        })
        .catch((err) => {});
    },
    saveRule() {
      if (this.preMaterialRuleType == 'add') {
        this.$message.success('备料规则配置成功');
        this.preMaterialRuleDialog.visible = false;
        this.$refs.add.isFifo = this.preMaterialRuleDialog.form.isFifo;
      }
    },
    cancelRule() {
      this.preMaterialRuleDialog.visible = false;
    },
    outBoundClose() {
      this.outBoundDialog.search.picker = '';
    },
    openUserCommonModal(params) {
      let { type } = params;
      switch (type) {
        // 领料人
        case 'picker':
          this.modalName = 'pickerModal';
          this.visibile = true;
          this.tableOption = {
            modalTitle: '选择用户管理信息（双击进行选择）',
            url: '/api/blade-system/user/page',
            isPage: true,
            rowSelectionType: 'single',
            menuWidth: 100,
            templateName: 'USER'
          };
          break;
        default:
          break;
      }
    },
    // 获取选择的模态框行数据
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'pickerModal':
          // this.outBoundDialog.form.picker = this._get(rowData, 'id', '');
          this.outBoundDialog.search.picker = this._get(rowData, 'realName', '');
          break;
        default:
          break;
      }
    },
    // 重新加载公用表格弹窗组件
    newKey() {
      this.timer = new Date().getTime();
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .outBoundDialog,
::v-deep .packBoxDialog,
::v-deep .baseDialog {
  .el-dialog__body {
    padding: 20px;
    .avue-crud__menu {
      display: none;
    }
    .title {
      font-size: 14px;
      font-weight: bold;
      margin: 5px 0;
      &:first-child {
        margin-top: 0;
      }
    }
    .titleBar {
      margin-bottom: 20px;
    }
  }
}

.tdStyle {
  background: #fafafa;
  font-weight: 700;
  color: #909399;
  text-align: right;
  width: 80px;
  padding-right: 20px;
  white-space: nowrap;
}

td {
  padding: 5px;
  border: 1px solid #ebeef5;
}
</style>
